package binary_search_tree

import "errors"

type FnCompare func(a interface{}, b interface{}) CompareResult

type tComparator struct {
	fnCompare FnCompare
}

func NewComparator(fn FnCompare) IComparator {
	if fn == nil {
		panic(gNullArgumentError)
	}

	return &tComparator{
		fnCompare: fn,
	}
}

func (me *tComparator) Compare(a interface{}, b interface{}) CompareResult {
	if a == nil || b == nil {
		panic(gNullArgumentError)
	}
	return me.fnCompare(a, b)
}

var gNullArgumentError = errors.New("null argument error")
